﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ADDDF.Infrastructure.DomainBase;

namespace ADDDF.Infrastructure.ChangeTracking
{
    public class ExceptionChangeRule :IChangeRule
    {
        private IEntity _entity;
        private Exception _exception;

        #region Constructor

        public ExceptionChangeRule(IEntity entity, Exception exception)
        {
            _entity = entity;
            _exception = exception;
        }

        #endregion

        #region Properties

        public IEntity Entity
        {
            get { return _entity; }
        }

        public Exception Exception
        {
            get { return _exception; }
        }

        #endregion

        #region IChangeRule Implementation

        public bool SameRuleAs(IChangeRule another)
        {
            if (!(another is ExceptionChangeRule))
                return false;

            ExceptionChangeRule a = (ExceptionChangeRule)another;

            if (!a.Entity.Equals(_entity))
                return false;

            if (!_exception.GetType().Name.Equals(a.Exception.GetType().Name)) 
                return false;

            return true;
        }

        public override int GetHashCode()
        {
            return _exception.GetType().GetHashCode();
        }

        #endregion

        
    }
}
